﻿using AnesSystem.Models;
using AnesSystem.Services;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnesSystem.ViewModels.Popup
{
    class WashNurseCtrlViewModel : BaseViewModel<WashNurseCtrlViewModel>
    {
        #region Variables
        //洗手一
        private string _xs1 = "";
        //洗手二
        private string _xs2 = "";
        //洗手三
        private string _xs3 = "";


        private String _disWashNurse = "";
        //手术医生集合
        private List<AccountModel> _operDoctor1ModelList = new List<AccountModel>();

        #endregion

        #region Constructor
        public WashNurseCtrlViewModel()
        {
            if (PatientLink.AnesthesiaRecord.Xshs1 != null && PatientLink.AnesthesiaRecord.Xshs1.Length == 24) Xs1 = PatientLink.AnesthesiaRecord.Xshs1;
            if (PatientLink.AnesthesiaRecord.Xshs2 != null && PatientLink.AnesthesiaRecord.Xshs2.Length == 24) Xs2 = PatientLink.AnesthesiaRecord.Xshs2;
            if (PatientLink.AnesthesiaRecord.Xshs3 != null && PatientLink.AnesthesiaRecord.Xshs3.Length == 24) Xs3 = PatientLink.AnesthesiaRecord.Xshs3;
        }

        #endregion

        #region Properties


        public string DisWashNurse
        {
            get
            {
                ConvertNurseDoctor();
                if (string.IsNullOrEmpty(_disWashNurse)) return "";
                return _disWashNurse;
            }

            set
            {
                _disWashNurse = value;
                RaisePropertyChanged("DisWashNurse");
            }
        }

        public string Xs1
        {
            get
            {
                return _xs1;
            }

            set
            {
                _xs1 = value;
            }
        }

        public string Xs2
        {
            get
            {
                return _xs2;
            }

            set
            {
                _xs2 = value;
            }
        }

        public string Xs3
        {
            get
            {
                return _xs3;
            }

            set
            {
                _xs3 = value;
            }
        }
        #endregion

        #region 依赖属性

        #endregion

        #region Event

        #endregion

        #region Private Methods
        private void ConvertNurseDoctor()
        {
            _disWashNurse = "";
            if (PatientLink.AnesthesiaRecord.Xshs1 != null && PatientLink.AnesthesiaRecord.Xshs1.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Xshs1));
                if (a != null) _disWashNurse += a.TrueName;
            }
            else
            {
                _disWashNurse += string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.Xshs1) ? "" : (PatientLink.AnesthesiaRecord.Xshs1);
            }
            if (PatientLink.AnesthesiaRecord.Xshs2 != null && PatientLink.AnesthesiaRecord.Xshs2.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Xshs2));
                if (a != null) _disWashNurse += "," + a.TrueName;
            }
            else
            {
                _disWashNurse += string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.Xshs2) ? "" : ("," + PatientLink.AnesthesiaRecord.Xshs2);
            }
            if (PatientLink.AnesthesiaRecord.Xshs3 != null && PatientLink.AnesthesiaRecord.Xshs3.Length == 24)
            {
                AccountModel a = DataManager.Instance.AccountList.ToList().Find(O => O.Id.ToString().Equals(PatientLink.AnesthesiaRecord.Xshs3));
                if (a != null) _disWashNurse += "," + a.TrueName;
            }
            else
            {
                _disWashNurse += string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.Xshs3) ? "" : ("," + PatientLink.AnesthesiaRecord.Xshs3);
            }
        }

        #endregion

        #region Public/Protected Methods
        public void Keep()
        {
            _xs1 = Util.ExtensionMethods.CheckAccount(_xs1, "护士");
            PatientLink.AnesthesiaRecord.Xshs1 = _xs1;
            _xs2 = Util.ExtensionMethods.CheckAccount(_xs2, "护士");
            PatientLink.AnesthesiaRecord.Xshs2 = _xs2;
            _xs3 = Util.ExtensionMethods.CheckAccount(_xs3, "护士");
            PatientLink.AnesthesiaRecord.Xshs3 = _xs3;

            PatientLinkService.Instance.AddUpdate(PatientLink);
            RaisePropertyChanged("DisWashNurse");
        }

      
        #endregion

        #region EventHandlers

        #endregion
    }
}
